package in.muton.edushare.components.tasks.electives.api;

import java.util.Comparator;
import java.util.List;

import com.edushare.common.dao.CurriculumDAO;
import com.edushare.common.dao.ElectivePreferenceDAO;
import com.edushare.common.orm.ORMInterface;
import com.edushare.common.vo.Batches;
import com.edushare.common.vo.ElectivePreference;
import com.edushare.common.vo.SemesterCourses;
import com.edushare.common.vo.Users;

public class ElectiveUserCompare implements Comparator<Users> {

	public ElectiveUserCompare(ORMInterface orm, Batches b, int electiveGroup){
		this.orm = orm;
		this.batch = b;
		this.electiveGroup = electiveGroup;
	}
	
	public int compare(Users o1, Users o2) {
		CurriculumDAO cDAO = new CurriculumDAO(orm);
		ElectivePreferenceDAO eDAO = new ElectivePreferenceDAO(orm);
		List<SemesterCourses> courseList = cDAO.getElectiveSemCourses(batch
				.getCurricula(), batch.getCurrentSemester(), electiveGroup);
		ElectivePreference p1 = eDAO.getPreference(o1, courseList.get(0), electiveGroup);
		ElectivePreference p2 = eDAO.getPreference(o2, courseList.get(0), electiveGroup);
		
		if(p1.getTimestamp().getTime() < p2.getTimestamp().getTime())
			return -1;
		else 
			return 1;
	}
	
	private ORMInterface orm;
	private Batches batch;
	private int electiveGroup;
}
